/*
 * @Descripttion: 
 * @version: 
 * @Author: cyj
 * @Date: 2023-01-01 17:59:56
 */
import request from "../../utils/request";

//通过手机号和密码登录   传入验证码时，密码会失效
export const loginByPhoneAndPwdOrCta = (phone, password, captcha = null) => request({
    url: '/login/cellphone',
    method: 'GET',
    params: {
        phone,
        password,
        captcha
    }
})
// export const loginStatus = () => request({
//     url: '/login/status',
//     method: 'get',
//     data: {
//         timestamp: Date.parse(new Date())
//     },
// })
export const loginStatus = (cookie) => request({
    url: `/login/status?timerstamp=${Date.now()}`,
    method: 'post',
    data: {
        cookie,
    },
})

//通过二维码登录
//1.获取二维码key
export const getQrKey = () => request({
    url: '/login/qr/key',
    method: 'GET',
    params: {
        timestamp: Date.parse(new Date())
    }
})
//2.生成二维码  key：上一个接口生成
export const getLoginQr = (key) => request({
    url: '/login/qr/create',
    method: 'GET',
    params: {
        key,
        qrimg: true, //返回二维码图片 base64 编码
        timestamp: Date.parse(new Date())
    }
})
//3.检测二维码的扫码状态  
//轮询此接口可获取二维码扫码状态,800 为二维码过期,801 为等待扫码,802 为待确认,803 为授权登录成功(803 状态码下会返回 cookies)
export const checkLoginQr = (key) => request({
    url: '/login/qr/check',
    method: 'GET',
    params: {
        key,
        timestamp: Date.parse(new Date())
    }
})

//通过手机验证码登录 | 注册时 使用的手机验证
//1.发送验证码
export const sendCaptcha = (phone) => request({
    url: '/captcha/sent',
    method: 'GET',
    params: {
        phone
    }
})
//2.验证验证码 
export const checkCaptcha = (phone, captcha) => request({
    url: '/captcha/verify',
    method: 'GET',
    params: {
        phone,
        captcha
    }
})

//用户注册
//1.注册(修改密码)
export const register = (phone, captcha, password, nickname) => request({
    url: '/register/cellphone',
    method: 'GET',
    params: {
        phone,
        captcha,
        password,
        nickname
    }
})

//2.检测手机号是否被注册
export const checkPhoneNum = (phone) => request({
    url: '/cellphone/existence/check',
    method: 'GET',
    params: {
        phone
    }
})

//获取用户账号信息
export const getUserAccount = () => request({
    url: '/user/account',
    params: {
        timestamp: Date.parse(new Date())
    }
})


//退出登录
export const logout = (cookie) => request({
    url: '/logout',
    method: 'post',
    data: {
        cookie
    }
})

